package com.woniu.demo;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class BeanFactory2 {
    private static Map objects = new HashMap();

    static {
        Properties properties = new Properties();
        try {
            properties.load(BeanFactory2.class.getClassLoader().getResourceAsStream("o.properties"));
            Set<String> keys = properties.stringPropertyNames();
            for (String key : keys) {
                String className = properties.getProperty(key);
                Object object = Class.forName(className).newInstance();
                objects.put(key, object);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public Object getBean(String classname) {
        return objects.get(classname);
    }
}
